package controller;

import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import controller.Vo.Vo;
import service.ServiceException;


@ControllerAdvice
public class ControllerExceptionHandler {
	private static final Logger logger = Logger.getLogger(ControllerExceptionHandler.class);
	
	@ExceptionHandler(ServiceException.class)
	@ResponseBody
	public Object handleServiceException(ServiceException ex){
		logger.error(ex.getMessage(), ex);
		return Vo.fail(ex.getMessage());
	}

	@ExceptionHandler(Exception.class)
	@ResponseBody
	public Object handleException(Exception ex){
		logger.error(ex.getMessage(), ex);
		return Vo.fail("服务器出错！");
	}
}
